#!/opt/bin/python2.6

import cgi,json
import MySQLdb
#from datetime import datetime, date, time

arguments  = cgi.FieldStorage()
num_chauf = arguments['num_chauf'].value
#num_chauf = "1"

print "Content-Type: application/json"
print

table1 = []
table2 = []

con = MySQLdb.connect(db ='mamaison',
                  user ='root',  host ='localhost', port =3306)
		   #cursorclass = MySQLdb.cursors.SSCursor)
cur = con.cursor()
cur.execute("select date,TRUNCATE(avg(c"+num_chauf+"target),2),TRUNCATE(avg(c"+num_chauf+"curtemp),2) from log where date >= date(DATE_SUB(now(), INTERVAL 1 DAY)) group by unix_timestamp(date) div 300 order by date")
rows = cur.fetchall()
for row in rows:
	table1.append([str(row[0]),row[1]])
	table2.append([str(row[0]),row[2]])
j = {}
j['num_chauf'] = num_chauf;
j['line1'] = table1
j['line2'] = table2
print json.dumps(j)

